package org.springblade.upgrade.nacos.constant;

import org.springblade.upgrade.nacos.model.NacosInstanceBean;
import org.springblade.upgrade.nacos.model.NacosInstanceInfo;

import java.util.List;

public class NacosUtil {
    /**
     * 服务名称转换
     *
     * @param instanceBean
     */
    public static void convert(NacosInstanceBean instanceBean) {
        if(instanceBean!=null){
            convert(instanceBean.getList());
        }

    }
    /**
     * 服务名称转换
     *
     * @param list
     */
    public static void convert(List<NacosInstanceInfo> list) {
        if (list != null && !list.isEmpty()) {
            for (NacosInstanceInfo item : list) {
                if (item.getServiceName() != null) {
                    int idx = item.getServiceName().lastIndexOf("@");
                    if (idx > 0) {
                        item.setServiceName(item.getServiceName().substring(idx + 1));
                    }
                }
            }
        }
    }
}
